/*
 * Copyright 2010 Alexander Ulizko
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.ulizko.template.soy.javaSrc;

import japa.parser.ast.body.MethodDeclaration;

/**
 * Method information container.
 * Used internally by {@link BlobJavaSrcAnalyzer}
 * to collect method's information from java code, generated by {@link SoyFileSetBuilder#compileToJavaSrc()}.
 * <p/>
 * @author Alexander <alexander@ulizko.com> Ulizko
 */
public class MethodDescription {
    private String methodName;
    private String packageName;
    private String className;
    private String soyFileName;
    private MethodDeclaration method;

    /**
     * Generated from scratch name of the method.
     * <p/>
     * To put it simple, it takes method name, generated by {@link com.google.template.soy.SoyToJavaSrcCompilerExperimental}
     * (like, for example, "com$sitename$template$pages$indexPage"),
     * splites it on "$" and takes last part as new method name.
     * @return New human-friendly method name.
     */
    public String getMethodName() {
        return methodName;
    }

    /**
     * Set method name. Used internally by {@link BlobJavaSrcAnalyzer}.
     * Read {@link #getMethodName()} about how does method name generated.
     * @param methodName Name of the method.
     */
    public void setMethodName(String methodName) {
        this.methodName = methodName;
    }

    /**
     * Returns package name.
     * Used internally by {@link BlobJavaSrcAnalyzer}
     * to find to which generated Java class this method belongs.
     * <p/>
     * Package name generated this way:
     * It takes it takes method name, generated by {@link com.google.template.soy.SoyToJavaSrcCompilerExperimental}
     * (like, for example, "com$sitename$template$pages$indexPage"),
     * splites it on "$". Last chunk it assumes as a method name, second-to-last as a class name,
     * and the rest as a java package.
     * @return Java package name, like "com.sitename.template".
     */
    public String getPackageName() {
        return packageName;
    }

    /**
     * Set package name.
     * Used internally by {@link BlobJavaSrcAnalyzer}.
     * Read {@link #getPackageName} about how package name generated.
     * @param packageName Java package name, like "com.sitename.template"
     */
    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    /**
     * Returns class name to which this method belongs.
     * Used internally by {@link BlobJavaSrcAnalyzer}.
     * <p/>
     * Class name generates this way:
     * It takes it takes method name, generated by {@link com.google.template.soy.SoyToJavaSrcCompilerExperimental}
     * (like, for example, "com$sitename$template$pages$indexPage"),
     * splites it on "$". Last chunk it assumes as a method name, second-to-last as a class name,
     * and the rest as a java package.
     * @return Valid java class name, like SomeTemplate or Page and so on.
     */
    public String getClassName() {
        return className;
    }

    /**
     * Set java class name.
     * Used internally by {@link BlobJavaSrcAnalyzer}.
     * <p/>
     * Read {@link #getClassName} about how class name is generated.
     * @param className Java class name, like SomeTemplate, or Page, or something like that.
     */
    public void setClassName(String className) {
        this.className = className;
    }

    /**
     * Returns soy filename, like simple.soy or adminPage.soy.
     * <p/>
     * Used internally by {@link JavaClassBlank} to generate JavaDocs for methods.
     * (I think, it is good idea to mark each generated method, where from it comes).
     * @return Soy fileName, like simple.soy.
     */
    public String getSoyFileName() {
        return soyFileName;
    }

    /**
     * Set soy fileName.
     * <p/>
     * Used internally by {@link JavaClassBlank} to generate JavaDocs for methods.
     * (I think, it is good idea to mark each generated method, where from it comes).
     * @param soyFileName  Soy fileName, like simple.soy or so.
     */
    public void setSoyFileName(String soyFileName) {
        this.soyFileName = soyFileName;
    }

    /**
     * Returns JavaParser's method.
     * Used internally by {@link JavaClassBlank} to build class body.
     * Of course, method name are already human-friendly.
     * @return Method with body, generated by {@link com.google.template.soy.SoyToJavaSrcCompilerExperimental}
     * but with human-readable method.
     */
    public MethodDeclaration getMethod() {
        return method;
    }

    /**
     * Set JavaParser's {@link japa.parser.ast.body.MethodDeclaration}.
     * Used internally by {@link BlobJavaSrcAnalyzer} to store method body for later usage. 
     * @param method Method, generated by {@link com.google.template.soy.SoyToJavaSrcCompilerExperimental} 
     */
    public void setMethod(MethodDeclaration method) {
        this.method = method;
    }
}